home *** CD-ROM | disk | FTP | other *** search
- drop procedure MakeSoundex
- go
- create procedure MakeSoundex(@Word varchar(255), @Code varchar(4) output)
- as
- declare @I Int
- declare @Ch Char
- declare @LastCh Char
- declare @MaxCodeLength SmallInt
- declare @LetterCodes char(26)
- begin
- if @Word is null begin
- select @Code = null
- return(0)
- end
- /*ABCDEFGHIJKLMNOPQRSTUVWXYZ*/
- select @LetterCodes = '01230120022455012623010202'
- select @MaxCodeLength = 4
- select @Code = Char(0), @LastCh = Char(0), @I = 1
- select @Word = Upper(@Word)
-
- while DataLength(@Code) <> @MaxCodeLength
- begin
- if @I > DataLength(@Word)
- select @Code = @Code + '0'
- else begin
- select @Ch = Substring(@Word, @I, 1)
- if (@Ch >= 'A') and (@Ch <= 'Z')
- if @Code = Char(0)
- select @Code = @Ch
- else begin
- select @Ch = Substring(@LetterCodes, Ascii(@Ch) - 64, 1)
- if (@Ch <> '0') and (@Ch <> @LastCh)
- select @Code = @Code + @Ch, @LastCh = @Ch
- end
- select @I = @I + 1
- end
- end
- end
- go
-
-